using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace TankGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class SimpleRenderer : Microsoft.Xna.Framework.DrawableGameComponent
    {
        struct TankSize {
            const float length = 1.5f;
            const float width = 1.0f;
        }

        DefaultEffect effect;
        VertexDeclaration vertexDecl;

        public List<Tank> tanks;

        // reference to main game
        Game game;

        public SimpleRenderer(Game game)
            : base(game)
        {
            this.game = game;
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            tanks = new List<Tank>();
           

            base.Initialize();
        }

        protected override void LoadContent()
        {
            effect = game.Content.Load<DefaultEffect>("Effects/Default");

            vertexDecl = new VertexDeclaration(new VertexElement[] {
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)
            });

            base.LoadContent();
        }

        float timeSinceLastTank;

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            timeSinceLastTank += gameTime.ElapsedGameTime.Seconds;
            if (timeSinceLastTank > 10)
            {
                Tank tank = new Tank(game);
                addTank(ref tank);
                tank = null;

                timeSinceLastTank = 0;
            }

            base.Update(gameTime);
        }

        public void addTank(ref Tank tank) 
        {
            tanks.Add(tank);
        }

        public void removeTank(ref Tank tank)
        {
            tanks.Remove(tank);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}
